using System.Collections.Generic;
using UnityEngine;

public class SkinCollection : MonoBehaviour
{
	private static SkinCollection instance;

	public Transform skinContainer;

	public SkinItem[] skinItems;

	public Dictionary<SkinCondition, string> conditionLabelTexts = new Dictionary<SkinCondition, string>
	{
		{
			SkinCondition.Kill,
			"单局击败 {0} 个敌人后解锁!"
		},
		{
			SkinCondition.Speed,
			"达到 {0} 自转速度后解锁!"
		},
		{
			SkinCondition.Survive,
			"存活 {0} 秒后解锁!"
		},
		{
			SkinCondition.TotalKill,
			"累计击败 {0} 个敌人后解锁!"
		}
	};

	public List<int> IndexList;

	public static SkinCollection Instance => instance;

	private void Awake()
	{
		if (instance == null)
		{
			instance = this;
		}
		else
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
		IndexList = new List<int>();
	}

	private void Start()
	{
		skinItems = skinContainer.GetComponentsInChildren<SkinItem>(includeInactive: false);
	}

	private void OnEnable()
	{
		SkinItem.OnSkinItemSelected += SkinItem_OnSkinItemSelected;
	}

	private void OnDisable()
	{
		SkinItem.OnSkinItemSelected -= SkinItem_OnSkinItemSelected;
	}

	public void CheckItems()
	{
		CheckItem(SkinCondition.Speed, ScoreManager.LastMass);
		CheckItem(SkinCondition.Kill, ScoreManager.LastKill);
		CheckItem(SkinCondition.Survive, (int)ScoreManager.LastSurviveTime);
		CheckItem(SkinCondition.TotalKill, ScoreManager.TotalKillCount);
	}

	private void CheckItem(SkinCondition condition, int value)
	{
		for (int i = 0; i < skinItems.Length; i++)
		{
			if (skinItems[i].skinType != SkinType.Condition || skinItems[i].Opened)
			{
				continue;
			}
			FidgetType fidgetType = GameManager.Instance.FidgetStore.fidgetTypes[skinItems[i].skinIndex];
			if (fidgetType.skinCondition == condition)
			{
				FidgetType fidgetType2 = GameManager.Instance.FidgetStore.fidgetTypes[skinItems[i].skinIndex];
				if (fidgetType2.limit <= value)
				{
					skinItems[i].OpenItem();
				}
			}
		}
	}

	private void SkinItem_OnSkinItemSelected(int itemIndex, int skinIndex)
	{
		skinItems[GameManager.Instance.SelectedItemIndex].DeselectItem();
		GameManager.Instance.SelectedItemIndex = itemIndex;
		GameManager.Instance.SelectedSkinIndex = skinIndex;
		skinItems[itemIndex].SelectItem();
	}
}
